Skip to main content

View and Export Billing Data

  1. In your billing project, view billing transaction history. What was your highest cost item so far?

    From left menu, go to Billing, then Transactions.

  2. Export your billing data to a Cloud Storage bucket.

    First create a Cloud Storage bucket from the StorageStorage menu; make it a regional bucket and choose your closest region.

    Next go back to BillingBilling Export.

    Click File Export.

    Type the name of your bucket, enter ‘billing_export’ in the prefix field, and set Format to CSV. Then click Enable Billing Export.

    Be aware that items in the bucket will not show until the next day.

  3. Export billing data to a BigQuery dataset.

    Go to BillingBilling Export.

    Select the project the BigQuery export will be in.

    If prompted, click the Go to BigQuery button to create a dataset.

    In BigQuery, create a new dataset. Call it 'billing_export'.

    Go back to the Billing Export screen (might have to click browser back button a few times).

    Choose project from drop down you just created a dataset in, and the dataset should be automatically found.

    Click the Enable BigQuery export button.

    Again, it will take some time for it to start populating information.

  4. Let’s run some sample queries against a public sample dataset:

    For all queries, go to BigQuery (any project), and click the red COMPOSE QUERY button to copy and paste the below queries.

    I will provide the SQL queries that you’ll copy and paste into a query field:

    First find all charges that were more than 3 dollars:

    SELECT product, resource_type, start_time, end_time,
    cost, project_id, project_name, project_labels_key, currency, currency_conversion_rate, usage_amount, usage_unit FROM `cloud-training-prod-bucket.arch_infra.billing_data` WHERE (cost > 3)

    Next let’s find which product had the highest total number of records:

    SELECT product, COUNT(*) FROM `cloud-training-prod-bucket.arch_infra.billing_data` GROUP BY product LIMIT 200

    Finally, let’s see which product most frequently cost more than a dollar:

    SELECT product, cost, COUNT(*) FROM `cloud-training-prod-bucket.arch_infra.billing_data` WHERE (cost > 1) GROUP BY cost, product LIMIT 200